package com.ruoyi.business.modbus.domain;

/**
 * Modbus TCP主站设备配置对象
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
public class ModbusTcpMasterDevice extends ModbusMasterDevice
{
    private static final long serialVersionUID = 1L;

    /** IP地址 */
    private String ipAddress;

    /** 端口号 */
    private Integer port;

    /** 是否封装 */
    private Boolean encapsulated = false;

    public ModbusTcpMasterDevice() {
        super();
    }

    public ModbusTcpMasterDevice(String deviceSN, String deviceName, 
                          String ipAddress, Integer port, Integer timeout, Integer retries) {
        super(deviceSN, deviceName, timeout, retries);
        this.ipAddress = ipAddress;
        this.port = port;
        this.encapsulated = false;
    }

    public ModbusTcpMasterDevice(String deviceSN, String deviceName, 
                          String ipAddress, Integer port, Boolean encapsulated, 
                          Integer timeout, Integer retries) {
        super(deviceSN, deviceName, timeout, retries);
        this.ipAddress = ipAddress;
        this.port = port;
        this.encapsulated = encapsulated;
    }

    /**
     * 创建TCP主站设备的静态工厂方法
     */
    public static ModbusTcpMasterDevice create(String deviceSN, String deviceName, 
                                        String ipAddress, Integer port) {
        return new ModbusTcpMasterDevice(deviceSN, deviceName, ipAddress, port, 3000, 3);
    }

    @Override
    public String getDeviceType() {
        return "TCP";
    }

    // Getters and Setters
    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Boolean getEncapsulated() {
        return encapsulated;
    }

    public void setEncapsulated(Boolean encapsulated) {
        this.encapsulated = encapsulated;
    }

    @Override
    public String toString() {
        return "ModbusTcpMasterDevice{" +
                "deviceSN='" + getDeviceSN() + '\'' +
                ", deviceName='" + getDeviceName() + '\'' +
                ", deviceType='" + getDeviceType() + '\'' +
                ", ipAddress='" + ipAddress + '\'' +
                ", port=" + port +
                ", encapsulated=" + encapsulated +
                ", timeout=" + getTimeout() +
                ", retries=" + getRetries() +
                '}';
    }
}
